package com.demo2do.boyle.common.entity.task;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.demo2do.boyle.common.entity.advertisement.Advertisement;
import com.demo2do.boyle.common.entity.customer.Customer;

/**
 * 
 *	任务投放用户表
 * 
 * @author mohanlan leo
 */
@Entity
@Table(name = "advertisement_customer")
public class Task {
	
	@Id
	@GeneratedValue
	private Integer id;
	
	@ManyToOne( optional = false, fetch = FetchType.LAZY)
	private Advertisement advertisement;
	
	@ManyToOne( optional=false, fetch=FetchType.LAZY)
	private Customer customer;
	
	@Enumerated(EnumType.ORDINAL)
	@Column( name="status" )
	private TaskStatus taskStatus;
	
	/** 审核人 */
	private String auditor;
	
	/** 可获奖金 */
	private Integer reward;
	
	private Date startDate;
	
	private Date endDate;
	
	/** 审核图片［微信／朋友圈 截图］*/
	private String screenshot;
	
	/** 审核时间 */
	private Date auditDate;
	
	/**
	 * the default construct
	 */
	public Task() {
		
	}
	
	/**
	 * 
	 * @param customer
	 * @param advertisement
	 */
	public Task(Customer customer, Advertisement advertisement) {
		this.customer = customer;
		this.advertisement = advertisement;
		this.endDate = advertisement.getEndDate();
	}
	
	/**
	 * 
	 * @return
	 */
	public Task initialize() {
		this.startDate = new Date();
		this.taskStatus = TaskStatus.CLAIMED;
		return this;
	}
	
	/**
	 * Upload auth screenshot
	 * @param screeanshot
	 * @return
	 */
	public Task uploadScreenshot(String screenshot) {
		this.screenshot = screenshot;
		this.taskStatus = TaskStatus.DONE;
		return this;
	}
	
	/**
	 * audit task Pass : set status and set auditor
	 * 
	 * @return
	 */
	public Task auditPass(String auditor) {
		this.taskStatus = TaskStatus.FINISH;
		this.auditor = auditor;
		this.auditDate = new Date();
		return this;
	}
	
	/**
	 * audit task unPass : set status and set auditor
	 * 
	 * @return
	 */
	public Task auditUnpass(String auditor) {
		this.taskStatus = TaskStatus.UNPASS;
		this.auditor = auditor;
		this.auditDate = new Date();
		return this;
	}

	/**
	 * @return the id
	 */
	public Integer getId() {
		return id;
	}

	/**
	 * @return the advertisement
	 */
	public Advertisement getAdvertisement() {
		return advertisement;
	}

	/**
	 * @return the customer
	 */
	public Customer getCustomer() {
		return customer;
	}

	/**
	 * @return the taskStatus
	 */
	public TaskStatus getTaskStatus() {
		return taskStatus;
	}

	/**
	 * @return the auditor
	 */
	public String getAuditor() {
		return auditor;
	}

	/**
	 * @return the reward
	 */
	public Integer getReward() {
		return reward;
	}

	/**
	 * @return the startDate
	 */
	public Date getStartDate() {
		return startDate;
	}

	/**
	 * @return the endDate
	 */
	public Date getEndDate() {
		return endDate;
	}

	/**
	 * @return the screenshot
	 */
	public String getScreenshot() {
		return screenshot;
	}

	/**
	 * @return the auditDate
	 */
	public Date getAuditDate() {
		return auditDate;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 * @param advertisement the advertisement to set
	 */
	public void setAdvertisement(Advertisement advertisement) {
		this.advertisement = advertisement;
	}

	/**
	 * @param customer the customer to set
	 */
	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	/**
	 * @param taskStatus the taskStatus to set
	 */
	public void setTaskStatus(TaskStatus taskStatus) {
		this.taskStatus = taskStatus;
	}

	/**
	 * @param auditor the auditor to set
	 */
	public void setAuditor(String auditor) {
		this.auditor = auditor;
	}

	/**
	 * @param reward the reward to set
	 */
	public void setReward(Integer reward) {
		this.reward = reward;
	}

	/**
	 * @param startDate the startDate to set
	 */
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	/**
	 * @param endDate the endDate to set
	 */
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	/**
	 * @param screenshot the screenshot to set
	 */
	public void setScreenshot(String screenshot) {
		this.screenshot = screenshot;
	}

	/**
	 * @param auditDate the auditDate to set
	 */
	public void setAuditDate(Date auditDate) {
		this.auditDate = auditDate;
	}
	
}
